#ifndef CENUM_H
#define CENUM_H

#include <QObject>
#include <QMetaEnum>

class MsgDatagram;
class CEnum : public QObject
{
    Q_OBJECT
public:
    CEnum(QObject *parent = nullptr);

    typedef   enum
    {
        PMAN,
        PWOMAN,

    }PATIENT_SEX;
     Q_ENUM(PATIENT_SEX)

    typedef enum
    {
        A,
        B,
        AB,
        O,
        RH
    }PATIENT_BLOOD_TYPE;
    Q_ENUM(PATIENT_BLOOD_TYPE)

    typedef enum
    {
        PHONE,
        SERVER,
        SURGERY
    }MSG_SOURCE;    //信息源设备种类
    Q_ENUM(MSG_SOURCE)


public:
    //字符串->枚举
    template<typename T>
    static T stringToEnum(QString str)
    {
        QMetaEnum meta = QMetaEnum::fromType<T>();
        return static_cast<T>(meta.keyToValue(str.toLatin1().constData()));
    };

    //枚举->字符串
    template<class TT>
    static QString enumtoString(TT em)
    {
        QMetaEnum meta = QMetaEnum::fromType<TT>();
        return meta.valueToKey(em);
    };


};

#endif // CENUM_H
